package com.cl.short_video_java.mp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.cl.short_video_java.common.Result;
import com.cl.short_video_java.config.mq.RabbitMqConfig;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Date;

/**
 * @Author 付
 * @Date 2024-11-30 21:18
 * @Version 1.0
 * @description
 * @since 1.0
 */
@Component
@Slf4j
public class VideoConsumer {

	@RabbitListener(queues = RabbitMqConfig.DIRECT_QUEUE)
	public void handle(Message message, Channel channel) throws IOException {
		byte[] body = message.getBody();
		String s = new String(body, StandardCharsets.UTF_8);
		log.info("违禁词--->{}", s);

		channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
	}


	@RabbitListener(queues = RabbitMqConfig.DELAY_QUEUE)
	public void receiveD(Message message, Channel channel) throws IOException {
		String msg = new String(message.getBody());
		log.info("当前时间：{},延时队列收到消息：{}", new Date().toString(), msg);
		System.out.println("获取的key-->" + msg);
		channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
	}
}
